use crate::${{moduleName}}::domain::vo::${{className}}VO;
use crate::{add_marco, export_excel_controller, update_marco, PageVO, RespVO};
use axum::Json;
use axum::extract::Path;
use axum::response::IntoResponse;
use macros::pre_authorize;
use rbatis::Page;
use crate::${{moduleName}}::domain::dto::{${{className}}AddDTO, ${{className}}PageDTO, ${{className}}UpdateDTO};
use crate::${{moduleName}}::${{moduleName|upper}}_CONTEXT;
use crate::${{moduleName}}::domain::mapper::${{className}};

//查询${{functionName}}列表
#[pre_authorize("${{permissionPrefix}}:list")]
pub async fn list(dto: Json<${{className}}PageDTO>) -> impl IntoResponse {
    let data = ${{moduleName|upper}}_CONTEXT.${{moduleName}}_${{business_name}}_service.page(&dto.0).await;
    let data = data.map(|d| Page::<${{className}}VO>::from(d));
    PageVO::from_result(&data).into_response()
}
//获取${{functionName}}详细信息
#[pre_authorize("${{permissionPrefix}}:query")]
pub async fn detail(${{pkColumn.columnName}}: Path<String>) -> impl IntoResponse {
    let ${{business_name}} = ${{moduleName|upper}}_CONTEXT.${{moduleName}}_${{business_name}}_service.detail(&${{pkColumn.columnName}}.0).await;
    let ${{business_name}} = ${{business_name}}.map(|d| ${{className}}VO::from(d));
    RespVO::from_result(&${{business_name}}).into_response()
}
//新增${{functionName}}
#[pre_authorize("${{permissionPrefix}}:add", user_cache)]
pub async fn add(dto: crate::ValidatedForm<${{className}}AddDTO>) -> impl IntoResponse {
    add_marco!(data, dto, user_cache, ${{className}});
    let res = ${{moduleName|upper}}_CONTEXT.${{moduleName}}_${{business_name}}_service.add(data).await;
    RespVO::from_result(&res).into_response()
}

//更新${{functionName}}
#[pre_authorize("${{permissionPrefix}}:edit", user_cache)]
pub async fn update(dto: crate::ValidatedForm<${{className}}UpdateDTO>) -> impl IntoResponse {
    update_marco!(data, dto, user_cache, ${{className}});
    let res = ${{moduleName|upper}}_CONTEXT.${{moduleName}}_${{business_name}}_service.update(data).await;
    RespVO::from_result(&res).into_response()
}

//删除${{functionName}}
#[pre_authorize("${{permissionPrefix}}:remove")]
pub async fn remove(${{pkColumn.columnName}}: Path<String>) -> impl IntoResponse {
    let rows_affected = ${{moduleName|upper}}_CONTEXT.${{moduleName}}_${{business_name}}_service.remove_batch(&${{pkColumn.columnName}}.0).await;
    RespVO::<u64>::judge_result(rows_affected, "删除成功！", "删除失败！")
        .into_response()
}
//导出${{functionName}}
export_excel_controller!(
    "${{permissionPrefix}}:export",
    ${{className}}PageDTO,
    ${{moduleName|upper}}_CONTEXT,
    ${{moduleName}}_${{business_name}}_service,
    export_as_excel_bytes
);